#include <iostream>
#include <cmath>
#include <unordered_map>
#include <string>

bool natural(int n) {
    if (n < 2) {
        return false;
    }
    for (int i = 2; i <= static_cast<int>(std::sqrt(n)) + 1; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

std::string numbername(const std::string& word) {
    std::unordered_map<std::string, std::string> numbermap = {
        {"zero", "0"}, {"one", "1"}, {"two", "2"}, {"three", "3"},
        {"four", "4"}, {"five", "5"}, {"six", "6"}, {"seven", "7"},
        {"eight", "8"}, {"nine", "9"}
    };
    auto it = numbermap.find(word);
    return (it != numbermap.end()) ? it->second : "";
}

int nearest_prime(int n) {
    if (n < 2) {
        return 2;
    }
    int l = n - 1;
    while (!natural(l)) {
        l--;
    }
    int w = n + 1;
    while (!natural(w)) {
        w++;
    }
    return (n - l <= w - n) ? l : w;
}

int main() {
    std::string input;
    std::getline(std::cin, input);
    std::string word;
    std::vector<std::string> words;
    std::stringstream ss(input);
    while (ss >> word) {
        words.push_back(word);
    }
    if (words.size() != 3) {
        std::cout << "Wrong input" << std::endl;
        return 1;
    }
    std::string num_str;
    for (const auto& w : words) {
        num_str += numbername(w);
    }
    if (!std::all_of(num_str.begin(), num_str.end(), ::isdigit) || (std::stoi(num_str) < 100 || std::stoi(num_str) > 999)) {
        std::cout << "Wrong input" << std::endl;
        return 1;
    }
    int num = std::stoi(num_str);
    std::cout << nearest_prime(num) << std::endl;
    return 0;
}

